package com.jason.platform.supervision.utils;

import android.content.Context;
import android.util.Log;
import com.jason.platform.supervision.BootApp;
import com.richmobtracker.RichMobPlatform;
import com.richmobtracker.RichMobTracker;

public class GAUtils {

	 private static final String TAG = GAUtils.class.getSimpleName();
	    
	    private static boolean isGAOpen = true;
	    
	    private static Context mContext;
	    
	    /**
	     * GA 初始化 [一句话功能简述]<BR>
	     * [功能详细描述]
	     */
	    public static void initGA(Context context, String trackId)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        mContext = context.getApplicationContext();
	        RichMobTracker.setRichMobTrackerPlatform(getApplication(),
	            RichMobPlatform.RichMobPlatFormGoogle,
	            trackId);
	        RichMobTracker.setLogEnabled(true);
	        RichMobTracker.setStatisticsEnabled(getApplication(), true);
	        RichMobTracker.setCrashReportEnabled(getApplication(), true);
	    }
	    
	    /**
	     * 上报appVersion
	     * [一句话功能简述]<BR>
	     * [功能详细描述]
	     * @param appVersion
	     */
	    public static void setAppVersion(String appVersion)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        Log.d(TAG, "appVersion:" + appVersion);
	        RichMobTracker.setAppVersion(appVersion);
	    }
	    
	    /**
	     * 上报内存信息
	     * [一句话功能简述]<BR>
	     * [功能详细描述]
	     * @param info
	     */
	    public static void setMemoryInfo(String info)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        Log.d(TAG, "memoryInfo:" + info);
	        RichMobTracker.setCustomDimension(1, info);
	    }
	    
	    /**
	     * 屏幕追踪
	     * [一句话功能简述]<BR>
	     * [功能详细描述]
	     * @param alias 屏幕名称
	     */
	    public static void onResume(String alias)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        Log.d(TAG, "onResume:" + alias);
	        RichMobTracker.onResume(alias);
	    }
	    
	    public static void onPause()
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        RichMobTracker.onPause();
	    }
	    
	    /**
	     * [功能详细描述]
	     * 
	     * @return 得到上下文对象
	     */
	    public static Context getApplication()
	    {
	        if (mContext != null)
	        {
	            return mContext;
	        }
	        else
	        {
	            return BootApp.getAppContext();
	        }
	    }
	    
	    /**
	     * 事件跟踪
	     * [功能详细描述]
	     * 
	     * @param category 自定义事件ID
	     * @param action 自定义事件的Action值
	     */
	    public static void submitEvent(String category, String action)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        RichMobTracker.tagEvent(category, action, null, null);
	        Log.d(TAG, "category:" + category + ", action:" + action);
	    }
	    
	    /**
	     * 事件跟踪
	     * [功能详细描述]
	     * 
	     * @param category 事件ID
	     * @param action 传入的action
	     * @param label 传入的label
	     */
	    public static void submitEvent(String category, String action, String label)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        RichMobTracker.tagEvent(category, action, label, null);
	        Log.d(TAG, "category:" + category + ", action:" + action
	            + ", label:" + label);
	    }
	    
	    /**
	     * 事件跟踪
	     * [功能详细描述]
	     * 
	     * @param category 事件ID
	     * @param action 传入的action
	     * @param label 传入的label
	     * @param value 传入的value
	     */
	    public static void submitEvent(String category, String action,
	        String label, Long value)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        RichMobTracker.tagEvent(category, action, label, value);
	        Log.d(TAG, "category:" + category + ", action:" + action
	            + ", label:" + label + ", value:" + value);
	    }
	    
	    /**
	     * 异常跟踪
	     * [一句话功能简述]<BR>
	     * [功能详细描述]
	     * @param context
	     * @param e
	     * @param isFatal
	     */
	    public static void submitCaughtException(Context context, Exception e,
	        Boolean isFatal)
	    {
	        if (!isGAOpen)
	        {
	            return;
	        }
	        RichMobTracker.tagCaughtException(context, e, isFatal);
	        Log.d(TAG, "Exception:" + e + ", Fatal:" + isFatal);
	    }

	    public void InitGA(Context context, String trackId)
	    {
	        initGA(context, trackId);
	    }

	    public void SubmitEvent(String category, String action, String label)
	    {
	        submitEvent(category, action, label);
	    }

	    public void SubmitCaughtException(Context context, Exception e,
	        Boolean isFatal)
	    {
	        submitCaughtException(context, e, isFatal);
	    }

	}
